;;; Mode: LISP; Syntax: Common-lisp; Package: ; Base: 10; Lowercase: Yes


(in-package :cl-user)

#+ccl
(eval-when (:compile-toplevel :load-toplevel :execute)
  (ccl:use-interface-dir :GL)
  #+darwin-target (open-shared-library "/System/Library/Frameworks/OpenGL.framework/OpenGL")
  #+windows-target (open-shared-library "opengl32.dll"))

(defpackage :lib.gl
  (:nicknames :gllib)
  (:export %external-vector enable-external-type-syntax get-pointer external-aref make-external-array make-vector pointer-size
	   external-vector-size
	   +pi/180+ +zero+ +one+ +epsilon+ +invpi+ inverse make-square-matrix mult-assign div-assign
	   quat-to-homogeneous-matrix
	   element-count element-type make-external-index-array quaternion
	   vector-to-quat
           array->gl-array external-vector external-array zero-vector %matrix copy-vector copy-matrix
	   set-column get-column set-row get-row unit-x-vector unit-y-vector unit-z-vector
	   cross unit-cross dot dot-product x y z vector= magnitude squared-magnitude print-matrix make-tensor-product
	   normalize orthonormalize generate-orthonormal-basis
	   mref set-mref m* m+ m- m/ mneg identity-matrix zero-matrix make-matrix matrix-cols matrix-rows
	   matrix3-by-rows matrix3-by-cols matrix-from-axis-angle
	   transpose augment-matrix find-eigenvalues find-eigenvectors
           with-gl with-gl-enabled with-matrix-mode slui
           texture-arb binding texture-width texture-height
	   quat-w quat-x quat-y quat-z quat-mult nquat-mult make-quat quat-magnitude euler-to-quat
	   euler-rotate-matrix rotation-matrix-to-quat quat-to-rotation-matrix axis-angle-to-quat 
	   quat-to-axis-angle 
	   defshader get-vertex-shader get-fragment-shader
	   shader-source-attributes
	   shader-attribute-type shader-attribute-location shader-attribute-name
	   define-vertex-list new-vertex-list
           )
  (:shadowing-import-from :iterate terminate)
  (:use :common-lisp :iterate #+ccl :ccl #+xlui :opengl :xml))


(defpackage :lib.chipmunk
  (:nicknames :chipmunk :cp)
  (:use :common-lisp :iterate )
  #+ccl (:import-from :ccl "MAKE-RECORD" "PREF" "RLET" "DEFCALLBACK"))

#-xlui
(defpackage :XML
  (:use :common-lisp)
					;  #+:sbcl 
;  (:import-from :sb-mop class-slots slot-definition-name
;		slot-definition-type slot-definition-initform)
  (:export  decode-xml-string encode-xml-string ;; CODEC
	    ;; classes
	    
	    xml-serializer ![cdata[ !doctype !--
	    ;; aggregation methods
	    
	    set-attribute-value add-subobject part-of add-object-to-slot cleanup-sub-object-slots
	    ;; print control methods
	    
	    xml-printable-as-attribute-value-p xml-printable-as-subelement-p map-object print-slot-with-name-p
	    print-slot-value-as-attribute print-slot-name-value-type-as-attribute print-slot-value-as-subelement print-slots
	    print-typed-attribute-value print-typed-subelement-value
	    print-default-value-attributes-p
	    slot-name->attribute-name
	    ;; reading
	     
	    load-object save-object finished-reading finished-reading-attributes read-typed-attribute-value
	    read-return-value without-xml-reader
	    attribute-name->slot-name
	    ;; instantiation
	     
	    duplicate
	    ;; do not export "File"
	     
	    file
	    ;; variables
	     
	    def-element-class-name xml-tag-name-string
	    ;; MOP
	     
	    class-slots find-slot-definition
	    ;; MOP goodies
	     
	    most-specific-class
	    ;; names
	     
	    xml-tag-name-symbol
	    ;; variables
	     
	    *xmlisp-packages*
	    *fallback-class-name-for-element-name-hook*
	    ;; types
	    path string-or-null integer-or-null
	    ;;
	    parse-file-name))

(when (find-package "XLUI")
  (defpackage :xlui-user
    (:import-from :xlui 
 		  animate application-window width height camera *reference-id-counter*
 		  draw agent-3d-view agents view broadcast-to-agents view-named with-glcontext
 		  prepare-opengl title name opengl-dialog eye-x eye-y eye-z center-x center-y center-z
		  up-x up-y up-z fovy aspect)
    (:use :common-lisp :iterate :lib.gl :xlui :xml :opengl)))

;(defpackage :nehe
;  (:use :common-lisp :ccl :iter #-xlui :gl #+xlui :opengl :cp))

(defpackage :app.dreaming-tree
  (:nicknames :app.dt :dreaming-tree)
  #+xlui
  (:import-from :xlui 
  		animate application-window width height camera *reference-id-counter*
  		draw agent-3d-view agents view broadcast-to-agents view-named with-glcontext
  		prepare-opengl title name opengl-dialog eye-x eye-y eye-z center-x center-y center-z
		up-x up-y up-z near far fovy aspect is-animated display aim-camera)
  #+xlui
  (:import-from :lui
		event animate-opengl-view-once view-event-handler view-left-mouse-down-event-handler
		view-left-mouse-dragged-event-handler key-event-handler key-event key-code set-size)
  (:shadowing-import-from :iterate finish)
  (:use :common-lisp :xml :iterate #+xlui :opengl #+xlui :xlui :lib.gl)) ; :clsql))

;;; To make the :dreaming-tree package XML aware uncomment the following:
(push (find-package :app.dreaming-tree) xml::*xmlisp-packages*)
;(push (find-package :xlui-user) xml::*xmlisp-packages*)

(defpackage :KR-DEBUG (:use :COMMON-LISP))
(defpackage :KR (:use :COMMON-LISP :KR-DEBUG))

;;;; Logging categories (where else can I put these?)



